//
// Converter.cs
//  
// Author:
//       Nicolai Mouritzen
// 
// Copyright (c) 2011 Nicolai Mouritzen
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;

namespace Educate0825
{
    /*
     * EXERCISE 1
     * Implement the Converter class properties so that all the tests succeed
     * use the following link http://www.mathsisfun.com/metric-imperial-conversion-charts.html
     * HINT - You need to use the *, / and % operators to solve this exercise
     *
     * EXERCISE 2
     * Add a Type parameter to the constructor of the class and add the following properties to the class
     *  - float Millimeters
     *  - int Meters
     *  - float Inches
     *  - int Feet
     *  - int Yards
     * You should also add a member float mMillimeters to the class to hold the distance value
     * HINT - You should use if() to determine which type you are holding
     *
     * EXERCISE 3
     * Add support for the TEMPERATURE type by adding the appropriate properties and members to the class
     * HINT - You need + and - in addition to what you have used previously.
     *
     * EXERCISE 4
     * Create a static function which can count the number of bits in an integer
     * HINT - You need to use while(), >> and & to solve this task
     */
    public class Converter
    {
        public enum Type
        {
            WEIGHT,
            DISTANCE,
            TEMPERATURE,
        }

        private float mGrams;
        public float Grams
        {
            get { return mGrams%1000; }
            set { mGrams = value; }
        }
        /*
         * Returns the full number of kilos in the converter
         */
        public int Kilograms { get; set; }
        public int Stones { get; set; }
        public int Pounds { get; set; }
        public float Ounces { get; set; }

        public Converter(float grams)
        {
            Grams = grams;
        }
    }

    [TestFixture]
    public class ConverterTest
    {
        [Test]
        public void ConvertGramToOunces1()
        {
            Converter c = new Converter(1);
            Assert.AreEqual( 0.0353, c.Ounces );
        }
        [Test]
        public void ConvertGramToOunces2()
        {
            Converter c = new Converter(1000);
            Assert.AreEqual( 3.53, c.Ounces );
        }
        [Test]
        public void ConvertGramToOunces3()
        {
            Converter c = new Converter(50000);
            Assert.AreEqual( 3.66843, c.Ounces );
        }
        [Test]
        public void ConvertGramToOunces4()
        {
            Converter c = new Converter(0);
            Assert.AreEqual( 0, c.Ounces );
        }
        [Test]
        public void ConvertGramToPounds1()
        {
            Converter c = new Converter(1);
            Assert.AreEqual( 0, c.Pounds );
        }
        [Test]
        public void ConvertGramToPounds2()
        {
            Converter c = new Converter(1000);
            Assert.AreEqual( 2, c.Pounds );
        }
        [Test]
        public void ConvertGramToStones1()
        {
            Converter c = new Converter(1);
            Assert.AreEqual( 0, c.Stones );
        }
        [Test]
        public void ConvertGramToStones2()
        {
            Converter c = new Converter(50000);
            Assert.AreEqual( 7, c.Stones );
        }
        [Test]
        public void ConvertGramToKilo1()
        {
            Converter c = new Converter(0);
            Assert.AreEqual( 0, c.Kilograms );
        }
        [Test]
        public void ConvertGramToKilo2()
        {
            Converter c = new Converter(1111);
            Assert.AreEqual( 1, c.Kilograms );
        }
        [Test]
        public void ConvertGramToGrams1()
        {
            Converter c = new Converter(1);
            Assert.AreEqual( 1, c.Grams );
        }
        [Test]
        public void ConvertGramToGrams2()
        {
            Converter c = new Converter(1111);
            Assert.AreEqual( 111, c.Grams );
        }
    }
}

